var t = getApp(), a = require("../../../utils/themeSkin/skinBehavior"), e = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ a, e ],
    data: {
        parentId: "",
        query: {
            page: 1,
            longitude: "",
            latitude: "",
            city: "",
            cityCode: "",
            travel_around_goods_type: "",
            is_recommand: "",
            category: "",
            title: "",
            basic_info: 1
        },
        active: 0,
        timer: null,
        secondaryIndex: 0,
        serviceShow: !1,
        stairClassify: [],
        secondary: [],
        categoriesGoodsList: [],
        showKefu: !1,
        customer_open: "",
        cservice: "",
        service_mobile: "",
        service_QRcode: "",
        zIndex: 100,
        isLoadMore: !0,
        totalPage: 0,
        total: 0,
        siteName: "",
        imageUrl: ""
    },
    onLoad: function(t) {
        wx.setNavigationBarColor({
            frontColor: "#ffffff",
            backgroundColor: this.data.themeBaseColor
        }), console.log(t, 11111), t.childrenId && this.setData({
            active: Number(t.childrenId),
            "query.city": t.city,
            "query.cityCode": t.cityCode,
            "query.longitude": t.longitude,
            "query.latitude": t.latitude,
            parentId: t.childrenId
        }), this.getCategory(), this.getKefu();
    },
    onReady: function() {
        var t = this;
        if (!this.data.query.latitude && !this.data.query.longitude) try {
            this._getLocation(function(a, e) {
                t.setData({
                    "query.latitude": e.lat,
                    "query.longitude": e.lng
                }), t.getGoodsList();
            });
        } catch (t) {
            this.getGoodsList();
        }
    },
    goodsNavTo: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageF/tourAround/tourAroundGoodsDetails/tourAroundGoodsDetails?goodsId=" + a
        });
    },
    secondaryOn: function(t) {
        var a = t.currentTarget.dataset.index;
        this.setData({
            secondaryIndex: a,
            "query.category": Number(this.data.secondary[a].id),
            "query.page": 1
        }), this.getGoodsList();
    },
    firstOn: function(t) {
        var a = t.detail.name;
        this.setData({
            parentId: a,
            "query.page": 1
        }), this.getCategory();
    },
    searchOn: function() {
        wx.navigateTo({
            url: "/packageF/tourAround/tourSearch/tourSearch?keyWord=".concat(this.data.query.title, "&city=").concat(this.data.query.city, "&cityCode=").concat(this.data.query.cityCode, "&latitude=").concat(this.data.query.latitude, "&longitude=").concat(this.data.query.longitude)
        });
    },
    getCategory: function() {
        var a = this, e = t.getNetAddresss("plugin.travel-around.frontend.goods.goods.getCategory");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    parentId: a.data.active,
                    stairClassify: e.data,
                    "query.category": Number(a.data.parentId)
                }), a.getGoodsList()) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getCategoryByParentId: function() {
        var a = this, e = {
            parent_id: this.data.parentId
        };
        wx.showLoading({
            title: "刷新中..."
        });
        var o = t.getNetAddresss("plugin.travel-around.frontend.goods.goods.getCategoryByParentId");
        t._getNetWork({
            url: o,
            data: e,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    var o = e.data;
                    a.setData({
                        secondary: e.data,
                        "query.category": Number(o[a.data.secondaryIndex].id)
                    }), a.getGoodsList();
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
                wx.hideLoading();
            },
            fail: function(t) {
                wx.hideLoading(), console.log(t);
            }
        });
    },
    getGoodsList: function() {
        var a = this, e = t.getNetAddresss("plugin.travel-around.frontend.goods.goods.getGoodsList");
        t._postNetWork({
            url: e,
            data: this.data.query,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    var o, i, s, r, d = e.basic_info;
                    a.data.totalPage = e.data.last_page, a.data.totalPage || (a.data.totalPage = 0), 
                    a.setData({
                        categoriesGoodsList: e.data.data,
                        siteName: null == d || null === (o = d.home) || void 0 === o || null === (i = o.mailInfo) || void 0 === i ? void 0 : i.name,
                        imageUrl: null == d || null === (s = d.home) || void 0 === s || null === (r = s.mailInfo) || void 0 === r ? void 0 : r.logo_url
                    });
                } else a.data.query.page = a.data.query.page - 1, a.isLoadMore = !1, wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getKefu: function() {
        var a = this, e = t.getNetAddresss("goods.customer-service.index");
        t._postNetWork({
            url: e,
            data: {
                goods_id: ""
            },
            success: function(t) {
                var e = t.data;
                1 == e.result && a.setData({
                    customer_open: 0 != e.data.customer_open,
                    showKefu: !1,
                    cservice: e.data.cservice,
                    service_QRcode: e.data.service_QRcode,
                    service_mobile: e.data.service_mobile
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    showService: function() {
        this.setData({
            showKefu: !0
        });
    },
    getMoreData: function() {
        var a = this;
        if (this.data.isLoadMore = !1, !(this.data.query.page >= this.data.totalPage)) {
            this.data.query.page = this.data.query.page + 1;
            var e = t.getNetAddresss("plugin.travel-around.frontend.goods.goods.getGoodsList");
            t._getNetWork({
                url: e,
                data: this.data.query,
                success: function(t) {
                    var e = t.data, o = e.data.data;
                    1 == e.result ? (a.data.isLoadMore = !0, a.setData({
                        categoriesGoodsList: a.data.categoriesGoodsList.concat(o)
                    })) : (a.data.query.page = a.data.query.page - 1, a.isLoadMore = !1, wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    }));
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        wx.showNavigationBarLoading(), wx.showLoading({
            title: "刷新中..."
        }), this.setData({
            "query.page": 1,
            storeName: ""
        }), this.getGoodsList();
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {
        return {
            title: "周边游-" + this.data.siteName,
            imageUrl: this.data.imageUrl,
            path: "/packageF/tourAround/categories/categories?childrenId=".concat(this.data.query.category, "&cityCode=").concat(this.data.query.cityCode, "&city=").concat(this.data.query.city, "&longitude=").concat(this.data.query.longitude, "&latitude=").concat(this.data.query.latitude)
        };
    },
    onShareTimeline: function() {
        return {
            title: "周边游-" + this.data.siteName,
            imageUrl: this.data.imageUrl,
            path: "/packageF/tourAround/categories/categories?childrenId=".concat(this.data.query.category, "&cityCode=").concat(this.data.query.cityCode, "&city=").concat(this.data.query.city, "&longitude=").concat(this.data.query.longitude, "&latitude=").concat(this.data.query.latitude)
        };
    }
});